package com.aba.cms.student;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CourseService {
    public static List<Course> getAllCourses() {
        List<Course> courses = new ArrayList<>();
        Connection connection = DBUtil.getConnection();
        String sql = "SELECT * FROM courses";
        try {
            PreparedStatement statement = connection.prepareStatement(sql);
            ResultSet resultSet = statement.executeQuery();
            while (resultSet.next()) {
                Course course = new Course(
                        resultSet.getInt("course_id"),
                        resultSet.getString("course_name"),
                        resultSet.getString("teacher_name")
//                        resultSet.getString("course_description")
                );
                courses.add(course);
            }
            resultSet.close();
            statement.close();
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return courses;
    }
}
